/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.cashmate.utilities;

import com.cashmate.hibernate.dao.*;
import com.cashmate.hibernate.pojo.Employees;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.http.HttpSession;
import org.apache.log4j.Logger;

/**
 * Web application lifecycle listener.
 * @author Dine
 */
public class StartUp implements ServletContextListener {

    private static Logger logger = Logger.getLogger(StartUp.class);

    public void contextInitialized(ServletContextEvent sce) {
        try {


            logger.info("Cashmate Server Up and Running");
            ServletContext sc = sce.getServletContext();

            BranchDAO branch = new BranchDAO();
            sc.setAttribute("branchDAO", branch);
            logger.info("Branches Data Access Object Instantiated");

            UserTypeDAO userType = new UserTypeDAO();
            sc.setAttribute("usertypeDAO", userType);
            logger.info("UserTypes Data Access Object Instantiated");

            EmployeeDAO employee = new EmployeeDAO();
            sc.setAttribute("employeeDAO", employee);
            logger.info("Employees Data Access Object Instantiated");

            UsertypeEmployeeDAO utypeEmp = new UsertypeEmployeeDAO();
            sc.setAttribute("useremployeeDAO", utypeEmp);
            logger.info("UserType_Employee Data Access Object Instantiated");

            UsertypeModuleDAO utypeModule = new UsertypeModuleDAO();
            sc.setAttribute("usermoduleDAO", utypeModule);
            logger.info("UserType_Module Data Access Object Instantiated");

            BorrowerDAO borrower = new BorrowerDAO();
            sc.setAttribute("borrowerDAO", borrower);
            logger.info("Borrower Data Access Object Instantiated");

            AreaDAO area = new AreaDAO();
            sc.setAttribute("areaDAO", area);
            logger.info("Area Data Access OBject Instantiated");

            AppraisalDAO appraisal = new AppraisalDAO();
            sc.setAttribute("appraisalDAO", appraisal);
            logger.info("Appraisal Data Access OBject Instantiated");

            BusinessDAO business = new BusinessDAO();
            sc.setAttribute("businessDAO", business);
            logger.info("Business Data Access OBject Instantiated");

            CharacterreferenceDAO character = new CharacterreferenceDAO();
            sc.setAttribute("characterreferenceDAO", character);
            logger.info("Characterreference Data Access OBject Instantiated");

            CreditinvestigationDAO credit = new CreditinvestigationDAO();
            sc.setAttribute("creditinvestigationDAO", credit);
            logger.info("Creditinvestigation Data Access OBject Instantiated");

            DependentDAO dependent = new DependentDAO();
            sc.setAttribute("dependentDAO", dependent);
            logger.info("Dependent Data Access OBject Instantiated");

            DocumentDAO document = new DocumentDAO();
            sc.setAttribute("documentDAO", document);
            logger.info("Document Data Access OBject Instantiated");

            LoanapplicationDAO loanapp = new LoanapplicationDAO();
            sc.setAttribute("loanapplicationDAO", loanapp);
            logger.info("Loanapplication Data Access OBject Instantiated");

            LoanswithotherbanksDAO loanswithother = new LoanswithotherbanksDAO();
            sc.setAttribute("loanswithotherbanksDAO", loanswithother);
            logger.info("Loanswithotherbanks Data Access OBject Instantiated");

            MonthlyincomeDAO monthlyincome = new MonthlyincomeDAO();
            sc.setAttribute("monthlyincomeDAO", monthlyincome);
            logger.info("Monthlyincome Data Access OBject Instantiated");

            RequirementDAO requirements = new RequirementDAO();
            sc.setAttribute("requirementDAO", requirements);
            logger.info("Requirement Data Access OBject Instantiated");

            ReputationDAO reputation = new ReputationDAO();
            sc.setAttribute("reputationDAO", reputation);
            logger.info("Reputation Data Access OBject Instantiated");

            TypeofcollateralDAO typeofcollateral = new TypeofcollateralDAO();
            sc.setAttribute("typeofcollateralDAO", typeofcollateral);
            logger.info("Typeofcollateral Data Access OBject Instantiated");

            SourceofincomeDAO source = new SourceofincomeDAO();
            sc.setAttribute("sourceofincomeDAO", source);
            logger.info("Sourceofincome Data Access OBject Instantiated");

            PaymentsDAO payments = new PaymentsDAO();
            sc.setAttribute("paymentsDAO", payments);
            logger.info("Payment Data Access Object Instantiated");

            LoansDAO loans = new LoansDAO();
            sc.setAttribute("loansDAO", loans);
            logger.info("Loans Data Access Object Instantiated");

            CollectionsDAO collections = new CollectionsDAO();
            sc.setAttribute("collectionsDAO", collections);
            logger.info("Collection Data Access Object Instantiated");

            DepositsDAO deposits = new DepositsDAO();
            sc.setAttribute("depositsDAO", deposits);
            logger.info("Deposits Data Access Object Instantiated");

            ModuleDAO module = new ModuleDAO();
            sc.setAttribute("moduleDAO", module);
            logger.info("Module Data Access Object Instantiated");

            RequestDAO request = new RequestDAO();
            sc.setAttribute("requestDAO", request);
            logger.info("Request Data Access Object Instantiated");

            MatrixcategoriesCriteriaDAO matrixcategoriescriteria = new MatrixcategoriesCriteriaDAO();
            sc.setAttribute("matrixcategoriesCriteriaDAO", matrixcategoriescriteria);
            logger.info("MatrixcategoriesCriteria Data Access Object Instantiated");

            MatrixcategoriesDAO matrixcategories = new MatrixcategoriesDAO();
            sc.setAttribute("matrixcategoriesDAO", matrixcategories);
            logger.info("Matrixcategories Data Access Object Instantiated");

            MatrixcriteriaDAO matrixcriteria = new MatrixcriteriaDAO();
            sc.setAttribute("matrixcriteriaDAO", matrixcriteria);
            logger.info("Matrixcriteria Data Access Object Instantiated");

            CreditmatrixDAO creditmatrix = new CreditmatrixDAO();
            sc.setAttribute("creditmatrixDAO", creditmatrix);
            logger.info("Creditmatrix Data Access Object Instantiated");

            BorrowerinfoDAO borrowerinfo = new BorrowerinfoDAO();
            sc.setAttribute("borrowerinfoDAO", borrowerinfo);
            logger.info("Borrowerinfo Data Access Object Instantiated");

            ProductDAO product = new ProductDAO();
            sc.setAttribute("productDAO", product);
            logger.info("Product Data Access Object Instantiated");

            CashcustodianreportDAO cashcustodianreport = new CashcustodianreportDAO();
            sc.setAttribute("cashcustodianreportDAO", cashcustodianreport);
            logger.info("Cashcustodianreport Data Access Object Instantiated");

            RatesDAO rates = new RatesDAO();
            sc.setAttribute("ratesDAO", rates);
            logger.info("Rates Data Access Object Instantiated");

            VoucherDAO voucher = new VoucherDAO();
            sc.setAttribute("voucherDAO", voucher);
            logger.info("Voucher Data Access Object Instantiated");

            VoucherRatesDAO voucherRates = new VoucherRatesDAO();
            sc.setAttribute("voucherRatesDAO", voucherRates);
            logger.info("Voucher Rates Data Access Object Instantiated");

            AdditionalfundDAO additionalfund = new AdditionalfundDAO();
            sc.setAttribute("additionalfundDAO", additionalfund);
            logger.info("Additionalfund Data Access Object Instantiated");

            BankdebitmemoDAO bankdebitmemo = new BankdebitmemoDAO();
            sc.setAttribute("bankdebitmemoDAO", bankdebitmemo);
            logger.info("Bankdebitmemo Data Access Object Instantiated");

            BankcreditmemoDAO bankcreditmemo = new BankcreditmemoDAO();
            sc.setAttribute("bankcreditmemoDAO", bankcreditmemo);
            logger.info("Bankcreditmemo Data Access Object Instantiated");

            CashdisbursementDAO cashdisbursement = new CashdisbursementDAO();
            sc.setAttribute("cashdisbursementDAO", cashdisbursement);
            logger.info("Cashdisbursement Data Access Object Instantiated");

            CashcustodianreportChecksDAO cashcustodianreportchecks = new CashcustodianreportChecksDAO();
            sc.setAttribute("cashcustodianreportchecksDAO", cashcustodianreportchecks);
            logger.info("CashcustodianreportChecks Data Access Object Instantiated");

            LoanverificationDAO loanverification = new LoanverificationDAO();
            sc.setAttribute("loanverificationDAO", loanverification);
            logger.info("Loanverification Data Access Object Instantiated");

            CheckDAO check = new CheckDAO();
            sc.setAttribute("checksDAO", check);
            logger.info("Check Data Access Object Instantiated");

            DccrDAO dccrdao = new DccrDAO();
            sc.setAttribute("dccrDAO", dccrdao);
            logger.info("DCCR Data Access Object Instantiated");

            PastDueListingDAO pastdao = new PastDueListingDAO();
            sc.setAttribute("pastdao", pastdao);
            logger.info("PastDueListing Data Access Object Instantiated");
            
            PerformanceDAO perfdao = new PerformanceDAO();
            sc.setAttribute("perfdao", perfdao);
            logger.info("Performance Data Access Object Instantiated");

            Map<Employees, HttpSession> USERS = new HashMap<Employees, HttpSession>();
            sc.setAttribute("USERS", USERS);
            logger.info("User Container Instantiated.");

            CollateralsDAO collateralsdao = new CollateralsDAO();
            sc.setAttribute("collateralsDAO", collateralsdao);
            logger.info("Collaterals Data Object Instantiated");

            DocumentspassedDAO documentspassed = new DocumentspassedDAO();
            sc.setAttribute("documentspassedDAO", documentspassed);
            logger.info("Documents Passed Data Access Object Instantiated");

            OthersourceofincomeDAO othersourceofincome = new OthersourceofincomeDAO();
            sc.setAttribute("othersourceofincomeDAO", othersourceofincome);
            logger.info("Other Source of Income Data Access Object Instantiated");

            FurnishingsandequipmentDAO furnandequip = new FurnishingsandequipmentDAO();
            sc.setAttribute("furnandequipDAO", furnandequip);
            logger.info("Furnishings and equipment Data Access Object Instantiated");

            InformantsDAO informants = new InformantsDAO();
            sc.setAttribute("informantsDAO", informants);
            logger.info("Informants Data Access Object Instantiated");

            LogDAO log = new LogDAO();
            sc.setAttribute("logDAO", log);
            logger.info("Log Data Access Object Instantiated");

            MatrixincomeDAO matrixincome = new MatrixincomeDAO();
            sc.setAttribute("matrixincomeDAO", matrixincome);
            logger.info("Matrix Income Data Access Object Instantiated");

            NotesreceivableDAO notesreceivable = new NotesreceivableDAO();
            sc.setAttribute("notesreceivableDAO", notesreceivable);
            logger.info("Notes receivable Data Access Object Instantiated");

            PropertyDAO property = new PropertyDAO();
            sc.setAttribute("propertyDAO", property);
            logger.info("Personal and Real Properties Data Access Object Instantiated");

        } catch (Exception e) {
            logger.fatal(e.getMessage(), e);
            System.exit(1);
        }
    }

    public void contextDestroyed(ServletContextEvent sce) {
        try {
            logger.info("Cashmate Server Shutdown");
        } catch (Exception e) {
            logger.fatal(e.getMessage(), e);
            System.exit(1);
        }
    }
}
